package edu.nf.exam.service.impl;

import com.github.pagehelper.PageInfo;
import edu.nf.exam.dao.MessageInfoDao;
import edu.nf.exam.dao.impl.MessageInfoDaoImpl;
import edu.nf.exam.entity.MessageInfo;
import edu.nf.exam.exception.DataAcessException;
import edu.nf.exam.service.MessageService;

import java.util.List;

/**
 * @Author : QYM
 * @create 2021/6/17
 * 消息信息表--业务接口实现类
 */
public class MessageServiceImpl implements MessageService {
    /**
     * 查询所有消息认证
     * @param messageInfo
     * @return
     */
    @Override
    public List<MessageInfo> checkSelectAll(MessageInfo messageInfo) {
        MessageInfoDao dao=new MessageInfoDaoImpl();
        try {
            List<MessageInfo> list = dao.selectAll(messageInfo);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAcessException("消息查询失败");
        }
    }

    /**
     * 修改认证
     * @param messageInfo
     * @return
     */
    @Override
    public void checkUpdate(MessageInfo messageInfo) {
        MessageInfoDao dao=new MessageInfoDaoImpl();
        try {
            dao.update(messageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAcessException("消息修改失败");
        }
    }

    /**
     * 添加（消息发送）
     * @param messageInfo
     */
    @Override
    public void add(MessageInfo messageInfo) {
        MessageInfoDao dao=new MessageInfoDaoImpl();
        try {
            dao.add(messageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAcessException("发送失败");
        }
    }

    /**
     * 分页查询所有消息
     * @param sendUserName
     * @param receiveUserName
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<MessageInfo> selectByPage(String sendUserName, String receiveUserName, Integer pageNum, Integer pageSize) {
        List<MessageInfo> list = new MessageInfoDaoImpl().selectByPage(sendUserName, receiveUserName, pageNum, pageSize);
        PageInfo<MessageInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
